package com.learning.algorithm.util;

import com.hankcs.hanlp.HanLP;
import lombok.extern.log4j.Log4j2;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: daqian_liao
 * @Date: 2018/12/12 19:07
 * @Version 1.0
 */
@Log4j2
public class SegmentationUtil {

    private static final String SPLIT_WORD = "`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？ ";

    public static List<String> getSplitWords(String sentence) {
        sentence = sentence.trim();
        return HanLP.segment(sentence).stream().map(a -> a.word)
                .filter(s -> !SPLIT_WORD.contains(s)).collect(Collectors.toList());
    }

    public static List<String> getMainWord(String sentence) {
        sentence = sentence.trim();
        return HanLP.extractKeyword(sentence, 3);
    }

    public static List<String> getPhraseWord(String sentence) {
        sentence = sentence.trim();

        return HanLP.extractPhrase(sentence, 3);
    }

    public static void main(String[] args) {
        /*log.info(SegmentationUtil.getSplitWords("张三应督促深圳蒹葭劳务公司马上整改"));
        log.info(SegmentationUtil.getMainWord("张三应督促深圳蒹葭劳务公司马上整改"));
        log.info(SegmentationUtil.getPhraseWord("张三应督促深圳蒹葭劳务公司马上整改"));

        log.info(SegmentationUtil.getSplitWords("张三应督促深圳桃夭劳务公司马上整改"));
        log.info(SegmentationUtil.getMainWord("张三应督促深圳逃之夭夭劳务公司马上整改"));
        log.info(SegmentationUtil.getPhraseWord("张三应督促深圳桃夭劳务公司马上整改"));

        log.info(SegmentationUtil.getSplitWords("张三应督促深圳硕鼠劳务公司马上整改"));
        log.info(SegmentationUtil.getMainWord("张三应督促深圳硕鼠劳务公司马上整改"));
        log.info(SegmentationUtil.getPhraseWord("张三应督促深圳硕鼠劳务公司马上整改"));*/

        log.info(SegmentationUtil.getSplitWords("中国张三应督促深圳桃夭劳务公司马上整改"));
    }


}
